let animation = null;
let map = null;
let lastTime = 0;
// 警报圈半径变化
let factor = -1;

export function initFrame(_map) {
  map = _map;
  animation = requestAnimationFrame(frame);
}

// 按帧渲染函数
function frame() {
  if (map && map.isStyleLoaded() && lastTime) {
    const timeNow = Date.now();

    // 警报圈半径变化
    if (map.getLayer('real-warn-circle')) {
      const oldSize = map.getLayoutProperty('real-warn-circle', 'icon-size');
      let newSize = oldSize + (timeNow - lastTime) / 1000 * factor;
      if (newSize > 1) {
        factor = -1;
        newSize = 1;
      } else if (newSize < 0.5) {
        factor = 1;
        if (newSize < 0) newSize = 0;
      }
      map.setLayoutProperty('real-warn-circle', 'icon-size', newSize);
    }
    
  }

  lastTime = Date.now();
  animation = requestAnimationFrame(frame);
}

export function clearFrame() {
  cancelAnimationFrame(animation);
  lastTime = 0;
}
